<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <title>dc-example</title>
    <script src="/libs/dc-sdk/dc.min.js"></script>
    <link href="/libs/dc-sdk/dc.min.css" type="text/css" rel="stylesheet" />
    <link href="../index.css" type="text/css" rel="stylesheet" />
  </head>

  <body>
    <div id="viewer-container" class="viewer-container"></div>
    <div class="btn-box">
      <ul>
        <li><button onclick="addPoint(100)">一百</button></li>
        <li><button onclick="addPoint(1000)">一千</button></li>
        <li><button onclick="addPoint(10000)">一万</button></li>
        <li><button onclick="addPoint(50000)">五万</button></li>
        <li><button onclick="addPoint(100000)">十万</button></li>
        <li><button onclick="removeAll()">清除</button></li>
      </ul>
    </div>
    <script>
      const generatePosition = (num) => {
        let list = []
        for (let i = 0; i < num; i++) {
          let lng = 120.38105869 + Math.random() * 0.5
          let lat = 31.10115627 + Math.random() * 0.5
          list.push(new DC.Position(lng, lat))
        }
        return list
      }
      DC.config.baseUrl = '../libs/dc-sdk/resources/'
      let viewer = new DC.Viewer('viewer-container')
      let baseLayer = DC.ImageryLayerFactory.createImageryLayer(
        DC.ImageryType.AMAP,
        {
          style: 'img',
          crs: 'WGS84',
        }
      )
      viewer.addBaseLayer(baseLayer)
      layer = new DC.VectorLayer('layer')
      viewer.addLayer(layer)
      let positions = generatePosition(100)
      positions.forEach((item) => {
        let billboard = new DC.Billboard(item, '../assets/icon/camera.png')
        layer.addOverlay(billboard)
      })
      viewer.flyToPosition(
        '120.8226729498609,31.268693185250438,114716.63624611919,0,-90'
      )

      function addPoint(num) {
        removeAll()
        let start = new Date().getTime()
        let positions = generatePosition(num)
        console.log(
          'create point time: ' + (new Date().getTime() - start) / 1000
        )
        start = new Date().getTime()
        positions.forEach((item) => {
          let billboard = new DC.Billboard(item, '../assets/icon/camera.png')
          billboard.on(DC.MouseEventType.CLICK, (e) => console.log(e))
          layer.addOverlay(billboard)
        })
        console.log('add point time: ' + (new Date().getTime() - start) / 1000)
      }

      function removeAll() {
        layer.clear()
      }
    </script>
  </body>
</html>
